"use strict";

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

/*
 * MikoPBX - free phone system for small business
 * Copyright © 2017-2024 Alexey Portnov and Nikolay Beketov
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 */

/* global globalRootUrl, PbxApi, globalPBXLicense, globalTranslate, UserMessage, globalPBXVersion, installStatusLoopWorker, marketplace */

/**
 * Manages the installation and updating of PBX extension modules from a repository.
 * It provides functionality to update individual modules or all modules at once,
 * and displays progress information to the user.
 *
 * @class installationFromRepo
 * @memberof module:PbxExtensionModules
 */
var installationFromRepo = {
  /**
   * The current version of the PBX system, with development version identifiers removed.
   * @type {string}
   */
  pbxVersion: globalPBXVersion.replace(/-dev/i, ''),

  /**
   * jQuery object for the button responsible for updating all installed modules.
   * @type {jQuery}
   */
  $btnUpdateAllModules: $('#update-all-modules-button'),

  /**
   * jQuery object for the block that contains the progress bar, used to indicate
   * the progress of module installation or updating processes.
   * @type {jQuery}
   */
  $progressBarBlock: $('#upload-progress-bar-block'),

  /**
   * jQuery object for the installation module modal form.
   * @type {jQuery}
   */
  $installModuleModalForm: $('#install-modal-form'),

  /**
   * Initializes the installationFromRepo module. Sets up event handlers for UI interactions
   * and hides UI elements that are not immediately needed.
   */
  initialize: function initialize() {
    installationFromRepo.initializeButtonEvents();
    installationFromRepo.$progressBarBlock.hide();
    installationFromRepo.$btnUpdateAllModules.hide(); // Until at least one update available
  },

  /**
   * Sets up event handlers for button clicks within the module.
   * This includes handling the installation and update of individual
   * modules as well as the bulk update functionality.
   */
  initializeButtonEvents: function initializeButtonEvents() {
    /**
     * Event handler for the download link click event.
     * @param {Event} e - The click event object.
     */
    $(document).on('click', 'a.download, a.update', function (e) {
      e.preventDefault();
      var $currentButton = $(e.target).closest('a.button');

      if (globalPBXLicense.trim() === '') {
        window.location = "".concat(globalRootUrl, "pbx-extension-modules/index#/licensing");
      } else {
        installationFromRepo.openInstallModuleModal($currentButton);
      }
    });
    installationFromRepo.$btnUpdateAllModules.on('click', installationFromRepo.updateAllModules);
  },

  /**
   * Opens the modal form for installing a module. This modal provides the user with information
   * about the module they are about to install, and confirms their action.
   *
   * @param {jQuery} $currentButton - The jQuery object of the button that was clicked to trigger this modal.
   */
  openInstallModuleModal: function openInstallModuleModal($currentButton) {
    var moduleUniqueId = $currentButton.data('uniqid');
    var releaseId = $currentButton.data('releaseid');
    installationFromRepo.$installModuleModalForm.modal({
      closable: false,
      onShow: function onShow() {
        var moduleName = $currentButton.closest('tr').data('name');
        var theForm = installationFromRepo.$installModuleModalForm;
        theForm.find('span.module-name').text(moduleName);
        var $installedModuleRow = $("tr.module-row[data-id=".concat(moduleUniqueId, "]"));

        if ($installedModuleRow.length > 0) {
          var _$currentButton$data;

          var installedVersion = $installedModuleRow.data('version');
          var newVersion = (_$currentButton$data = $currentButton.data('version')) !== null && _$currentButton$data !== void 0 ? _$currentButton$data : installedVersion;

          if (marketplace.versionCompare(newVersion, installedVersion) > 0) {
            theForm.find('span.action').text(globalTranslate.ext_UpdateModuleTitle);
            theForm.find('div.description').html(globalTranslate.ext_ModuleUpdateDescription);
          } else {
            theForm.find('span.action').text(globalTranslate.ext_DowngradeModuleTitle);
            theForm.find('div.description').html(globalTranslate.ext_ModuleDowngradeDescription);
          }
        } else {
          theForm.find('span.action').text(globalTranslate.ext_InstallModuleTitle);
          theForm.find('div.description').html(globalTranslate.ext_ModuleInstallDescription);
        }
      },
      onDeny: function onDeny() {
        $('a.button').removeClass('disabled');
        return true;
      },
      onApprove: function onApprove() {
        $('a.button').addClass('disabled');
        var params = {
          uniqid: moduleUniqueId,
          releaseId: releaseId,
          channelId: installStatusLoopWorker.channelId
        };
        $("#modal-".concat(params.uniqid)).modal('hide');
        var $moduleButtons = $("a[data-uniqid=".concat(params.uniqid));
        $moduleButtons.removeClass('disabled');
        $moduleButtons.find('i').removeClass('download').removeClass('redo').addClass('spinner loading');
        $('tr.table-error-messages').remove();
        $('tr.error').removeClass('error');
        PbxApi.ModulesInstallFromRepo(params, function (response) {
          console.debug(response);

          if (response.result === true) {
            $('html, body').animate({
              scrollTop: installationFromRepo.$progressBarBlock.offset().top
            }, 2000);
          }
        });
        return true;
      }
    }).modal('show');
  },

  /**
   * Initiates the process of updating all installed modules. This function is triggered by the user
   * clicking the 'Update All' button. It first disables UI elements to prevent further user actions
   * and then calls the API to start the update process.
   *
   * @param {Event} e - The click event object associated with the 'Update All' button click.
   */
  updateAllModules: function updateAllModules(e) {
    e.preventDefault();
    $('a.button').addClass('disabled');
    var $currentButton = $(e.target).closest('a');
    installationFromRepo.openUpdateAllModulesModal($currentButton);
  },

  /**
   * Opens a modal confirmation dialog when updating all modules. This dialog informs the user about
   * the update process and asks for confirmation to proceed with updating all installed modules.
   *
   * @param {jQuery} $currentButton - The jQuery object of the button that was clicked to trigger this modal.
   */
  openUpdateAllModulesModal: function openUpdateAllModulesModal($currentButton) {
    installationFromRepo.$installModuleModalForm.modal({
      closable: false,
      onShow: function onShow() {
        var theForm = installationFromRepo.$installModuleModalForm;
        theForm.find('span.action').text(globalTranslate.ext_UpdateAllModulesTitle);
        theForm.find('span.module-name').text('');
        theForm.find('div.description').html(globalTranslate.ext_UpdateAllModulesDescription);
      },
      onDeny: function onDeny() {
        $('a.button').removeClass('disabled');
        return true;
      },
      onApprove: function onApprove() {
        $('a.button').addClass('disabled');
        $currentButton.removeClass('disabled');
        $currentButton.closest('i.icon').removeClass('redo').addClass('spinner loading');
        var uniqueModulesForUpdate = new Set();
        $('a.update').each(function (index, $button) {
          uniqueModulesForUpdate.add($($button).data('uniqid'));
        });
        var params = {
          channelId: installStatusLoopWorker.channelId,
          modulesForUpdate: _toConsumableArray(uniqueModulesForUpdate)
        };
        PbxApi.ModulesUpdateAll(params, function (response) {
          console.debug(response);
        });
        $('tr.table-error-messages').remove();
        $('tr.error').removeClass('error');
        return true;
      }
    }).modal('show');
  }
}; // Initializes the installationFromRepo module when the document is ready,
// preparing the extension modules management UI.

$(document).ready(function () {
  installationFromRepo.initialize();
});
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9QYnhFeHRlbnNpb25Nb2R1bGVzL3BieC1leHRlbnNpb24tbW9kdWxlLWluc3RhbGwtZnJvbS1yZXBvLmpzIl0sIm5hbWVzIjpbImluc3RhbGxhdGlvbkZyb21SZXBvIiwicGJ4VmVyc2lvbiIsImdsb2JhbFBCWFZlcnNpb24iLCJyZXBsYWNlIiwiJGJ0blVwZGF0ZUFsbE1vZHVsZXMiLCIkIiwiJHByb2dyZXNzQmFyQmxvY2si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b24uZGF0YSgndmVyc2lvbicpPz9pbnN0YWxsZWRWZXJzaW9uO1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG1hcmtldHBsYWNlLnZlcnNpb25Db21wYXJlKG5ld1ZlcnNpb24sIGluc3RhbGxlZFZlcnNpb24pPjApe1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoZUZvcm0uZmluZCgnc3Bhbi5hY3Rpb24nKS50ZXh0KGdsb2JhbFRyYW5zbGF0ZS5leHRfVXBkYXRlTW9kdWxlVGl0bGUpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoZUZvcm0uZmluZCgnZGl2LmRlc2NyaXB0aW9uJykuaHRtbChnbG9iYWxUcmFuc2xhdGUuZXh0X01vZHVsZVVwZGF0ZURlc2NyaXB0aW9uKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhlRm9ybS5maW5kKCdzcGFuLmFjdGlvbicpLnRleHQoZ2xvYmFsVHJhbnNsYXRlLmV4dF9Eb3duZ3JhZGVNb2R1bGVUaXRsZSk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhlRm9ybS5maW5kKCdkaXYuZGVzY3JpcHRpb24nKS5odG1sKGdsb2JhbFRyYW5zbGF0ZS5leHRfTW9kdWxlRG93bmdyYWRlRGVzY3JpcHRpb24pO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhlRm9ybS5maW5kKCdzcGFuLmFjdGlvbicpLnRleHQoZ2xvYmFsVHJhbnNsYXRlLmV4dF9JbnN0YWxsTW9kdWxlVGl0bGUpO1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhlRm9ybS5maW5kKCdkaXYuZGVzY3JpcHRpb24nKS5odG1sKGdsb2JhbFRyYW5zbGF0ZS5leHRfTW9kdWxlSW5zdGFsbERlc2NyaXB0aW9uKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgb25EZW55OiAoKSA9PiB7XG4gICAgICAgICAgICAgICAgICAgICQoJ2EuYnV0dG9uJykucmVtb3ZlQ2xhc3MoJ2Rpc2FibGVkJyk7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgb25BcHByb3ZlOiAoKSA9PiB7XG4gICAgICAgICAgICAgICAgICAgICQoJ2EuYnV0dG9uJykuYWRkQ2xhc3MoJ2Rpc2FibGVkJyk7XG5cbiAgICAgICAgICAgICAgICAgICAgY29uc3QgcGFyYW1zID0ge1xuICAgICAgICAgICAgICAgICAgICAgICAgdW5pcWlkOiBtb2R1bGVVbmlxdWVJZCxcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlbGVhc2VJZDogcmVsZWFzZUlkLFxuICAgICAgICAgICAgICAgICAgICAgICAgY2hhbm5lbElkOiBpbnN0YWxsU3RhdHVzTG9vcFdvcmtlci5jaGFubmVsSWRcbiAgICAgICAgICAgICAgICAgICAgfTtcblxuICAgICAgICAgICAgICAgICAgICAkKGAjbW9kYWwtJHtwYXJhbXMudW5pcWlkfWApLm1vZGFsKCdoaWRlJyk7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0ICRtb2R1bGVCdXR0b25zID0gJChgYVtkYXRhLXVuaXFpZD0ke3BhcmFtcy51bmlxaWR9YCk7XG5cbiAgICAgICAgICAgICAgICAgICAgJG1vZHVsZUJ1dHRvbnMucmVtb3ZlQ2xhc3MoJ2Rpc2FibGVkJyk7XG4gICAgICAgICAgICAgICAgICAgICRtb2R1bGVCdXR0b25zLmZpbmQoJ2knKVxuICAgICAgICAgICAgICAgICAgICAgICAgLnJlbW92ZUNsYXNzKCdkb3dubG9hZCcpXG4gICAgICAgICAgICAgICAgICAgICAgICAucmVtb3ZlQ2xhc3MoJ3JlZG8nKVxuICAgICAgICAgICAgICAgICAgICAgICAgLmFkZENsYXNzKCdzcGlubmVyIGxvYWRpbmcnKTtcblxuICAgICAgICAgICAgICAgICAgICAkKCd0ci50YWJsZS1lcnJvci1tZXNzYWdlcycpLnJlbW92ZSgpO1xuICAgICAgICAgICAgICAgICAgICAkKCd0ci5lcnJvcicpLnJlbW92ZUNsYXNzKCdlcnJvcicpO1xuXG4gICAgICAgICAgICAgICAgICAgIFBieEFwaS5Nb2R1bGVzSW5zdGFsbEZyb21SZXBvKHBhcmFtcywgKHJlc3BvbnNlKSA9PiB7XG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmRlYnVnKHJlc3BvbnNlKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChyZXNwb25zZS5yZXN1bHQgPT09IHRydWUpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAkKCdodG1sLCBib2R5JykuYW5pbWF0ZSh7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNjcm9sbFRvcDogaW5zdGFsbGF0aW9uRnJvbVJlcG8uJHByb2dyZXNzQmFyQmxvY2sub2Zmc2V0KCkudG9wLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0sIDIwMDApO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB9KTtcblxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgfSlcbiAgICAgICAgICAgIC5tb2RhbCgnc2hvdycpO1xuICAgIH0sXG5cbiAgICAvKipcbiAgICAgKiBJbml0aWF0ZXMgdGhlIHByb2Nlc3Mgb2YgdXBkYXRpbmcgYWxsIGluc3RhbGxlZCBtb2R1bGVzLiBUaGlzIGZ1bmN0aW9uIGlzIHRyaWdnZXJlZCBieSB0aGUgdXNlclxuICAgICAqIGNsaWNraW5nIHRoZSAnVXBkYXRlIEFsbCcg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ICAgJGN1cnJlbnRCdXR0b24ucmVtb3ZlQ2xhc3MoJ2Rpc2FibGVkJyk7XG4gICAgICAgICAgICAgICAgICAgICRjdXJyZW50QnV0dG9uLmNsb3Nlc3QoJ2kuaWNvbicpXG4gICAgICAgICAgICAgICAgICAgICAgICAucmVtb3ZlQ2xhc3MoJ3JlZG8nKVxuICAgICAgICAgICAgICAgICAgICAgICAgLmFkZENsYXNzKCdzcGlubmVyIGxvYWRpbmcnKTtcblxuICAgICAgICAgICAgICAgICAgICBsZXQgdW5pcXVlTW9kdWxlc0ZvclVwZGF0ZSA9IG5ldyBTZXQoKTtcbiAgICAgICAgICAgICAgICAgICAgJCgnYS51cGRhdGUnKS5lYWNoKChpbmRleCwgJGJ1dHRvbik9PntcbiAgICAgICAgICAgICAgICAgICAgICAgIHVuaXF1ZU1vZHVsZXNGb3JVcGRhdGUuYWRkKCQoJGJ1dHRvbikuZGF0YSgndW5pcWlkJykpO1xuICAgICAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICAgICAgY29uc3QgcGFyYW1zID0ge1xuICAgICAgICAgICAgICAgICAgICAgICAgY2hhbm5lbElkOiBpbnN0YWxsU3RhdHVzTG9vcFdvcmtlci5jaGFubmVsSWQsXG4gICAgICAgICAgICAgICAgICAgICAgICBtb2R1bGVzRm9yVXBkYXRlOiBbLi4udW5pcXVlTW9kdWxlc0ZvclVwZGF0ZV0sXG4gICAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgICAgIFBieEFwaS5Nb2R1bGVzVXBkYXRlQWxsKHBhcmFtcywgKHJlc3BvbnNlKSA9PiB7XG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmRlYnVnKHJlc3BvbnNlKTtcbiAgICAgICAgICAgICAgICAgICAgfSk7XG5cbiAgICAgICAgICAgICAgICAgICAgJCgndHIudGFibGUtZXJyb3ItbWVzc2FnZXMnKS5yZW1vdmUoKTtcbiAgICAgICAgICAgICAgICAgICAgJCgndHIuZXJyb3InKS5yZW1vdmVDbGFzcygnZXJyb3InKTtcblxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgfSlcbiAgICAgICAgICAgIC5tb2RhbCgnc2hvdycpO1xuICAgIH0sXG5cbn07XG5cbi8vIEluaXRpYWxpemVzIHRoZSBpbnN0YWxsYXRpb25Gcm9tUmVwbyBtb2R1bGUgd2hlbiB0aGUgZG9jdW1lbnQgaXMgcmVhZHksXG4vLyBwcmVwYXJpbmcgdGhlIGV4dGVuc2lvbiBtb2R1bGVzIG1hbmFnZW1lbnQgVUkuXG4kKGRvY3VtZW50KS5yZWFkeSgoKSA9PiB7XG4gICAgaW5zdGFsbGF0aW9uRnJvbVJlcG8uaW5pdGlhbGl6ZSgpO1xufSk7Il19